package com.gxa.ssm340.config;

import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;


/**
 * 我们来设计一个DataSource的bean创建，并且能注册到spring中
 * 1.添加@Bean注解，表示该对象被注册到容器中
 * 2.还需要当前所在的类先注册到spring容器,更适合使用@Configuration
 * 3.@Bean可以设定名称（自定义）,使用效果完全一致
 * @author Lenovo
 */

@Configuration
public class DataSourceConfig {

    @Value("${pooled.url}")
    private  String url ;
    @Value("${pooled.driver}")
    private  String driver ;
    @Value("${pooled.username}")
    private  String username;
    @Value("${pooled.password}")
    private  String password ;


    @Bean("dataSource2")
    public DataSource getDataSource(){
        PooledDataSource dataSource = new PooledDataSource();

        dataSource.setUrl(url);
        dataSource.setDriver(driver);
        dataSource.setUsername(username);
        dataSource.setPassword(password);

        return dataSource;
    }
}
